package com.ca.demo.service;

import com.ca.demo.BaseTestCase;
import com.ca.demo.common.utils.FileUtil;
import com.ca.demo.controller.maintain.Icon;
import com.ca.demo.service.maintain.IconService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author XieLei
 * @Date 2017/6/26 16:44
 */
public class IconServiceTestCase extends BaseTestCase {

    @Autowired
    private IconService iconService;

    @Test
    public void initIconData() {
        // .fa-arrows:before {

        String regex = "^\\.(?<name>.*?):before\\s*\\{";
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);

        String content = FileUtil.readFromFile("E:\\project\\admin\\src\\main\\resources\\static\\font-awesome\\css\\font-awesome.css");

        Matcher matcher = pattern.matcher(content);

        List<String> matchList = new ArrayList<>();
        while(matcher.find()) {
            matchList.add(matcher.group("name"));
        }
        for (String itemName : matchList) {
            Icon icon = new Icon();
            icon.setDisplayName(itemName);
            icon.setClassName("fa " + itemName);
            icon.setSourceType("FontAwesome");
//            iconService.save(icon);
        }
    }


}
